#include "rts_server.hpp"

#include <boost/foreach.hpp>
#include <standard.hpp>

rts_server::rts_server(boost::asio::io_service& io_service,
                       int port,
                       boost::shared_ptr<logger> log,
                       boost::shared_ptr<client_factory> factory,
                       const std::string& origin,
                       const std::string& location,
                       boost::shared_ptr<message_receiver> receiver) :
    web_socket_server(io_service,
        port,
        log,
        factory,
        origin,
        location,
        receiver)
{
}

void rts_server::start_game(std::vector<boost::shared_ptr<rts_client> >& players)
{
    game_ptr g(new game(players));
    g->game_over().connect(boost::bind(&rts_server::game_over, this, _1));
    _games.push_back(g);
}

void rts_server::game_over(game_ptr (g))
{
    _games.erase(std::find(_games.begin(), _games.end(), g));
}
